package Food_controller;

import java.io.IOException;

import Food_model.Food;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
@WebServlet("/update")
public class UpdateController extends HttpServlet {

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		this.doPost(req, resp);
	}

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		req.setCharacterEncoding("utf-8");
		String foodid= req.getParameter("foodid");
		String foodname= req.getParameter("foodname");
		String foodunit=req.getParameter("foodunit");
		String foodprice= req.getParameter("foodprice");
		//創建Product對象
		Food fd=new Food();
		fd.setFoodid(foodid);
		fd.setFoodname(foodname);
		fd.setFoodunit(foodunit);
		fd.setFoodprice(Double.parseDouble(foodprice));
		//调用Product對象更新方法
		fd.updateFood();
		req.getRequestDispatcher("right.jsp").forward(req, resp);
		
	}

}

